'use strict';

const Validate = require('../util/validate');
const common = require('../util/common');

module.exports = {
  validate(value) {
    return new Validate(value);
  },
  // checkArr = [ value | { value, type } ]
  checkAND(checkArr = []) {
    if (Array.isArray(checkArr)) {
      return checkArr.every(item => {
        if (common.isObject(item)) {
          const check = new Validate(item.value);
          if (common.isFunction(check[item.type])) {
            return check[item.type]();
          }
          return !!item.value;
        }
        return !!item;
      });
    }
    return false;
  },
  paging(page = 1, pageSize = 10) {
    return {
      limit: pageSize,
      offset: (page - 1) * pageSize,
    };
  },
};
